<?php
/**
 * Created by PhpStorm.
 * User: 赵修宇
 * Date: 2018/5/20
 * Time: 14:28
 */
namespace Home\Model;

use Think\Model;

class RecommendModel extends Model
{
    public function pri($data)
    {
        echo '<pre>';
        print_r($data);
        echo '</pre>';
    }

    public function recommend($pointPeople, $pointProduct)
    {
        $res = $this->recursive($pointPeople, $pointProduct);
        $this->pri($res);die;
    }

    /**
     * @param $arr
     * @param $other
     * @param int $num
     */
    public function recursive($arr, $other, $num = 0)
    {
        if ($num >= count($arr) || $num >= count($other)){
            var_dump($num, count($arr), count($other));
            return false;
        }
        $arr_slice = array_slice($arr, $num, 5);
        $other_slice = array_slice($other, $num, 5);
        $int = array_intersect($arr_slice, $other_slice);
        if (!empty($int)){
            return $int;
        }
        if(!$int = $this->recursive($arr, $other, $num + 5)){
            return false;
        }else{
            return $int;
        }
    }

    public function getRecommend()
    {
        return [
            ['name' => ' 红米5A 全网通版 3GB内存 32GB ', 'price' => '699'],
            ['name' => ' 红米Note 5 全网通版 4GB内存 64GB ', 'price' => '1399'],
            ['name' => ' 红米5 移动4G+版 2GB内存 ', 'price' => '799'],
            ['name' => ' 小米MIX 2S 全网通版 8GB内存 陶瓷尊享版 256GB ', 'price' => '3999'],
            ['name' => ' 小米6 全网通版 4GB内存 ', 'price' => '2299'],
            ['name' => ' 小米MIX 2S 艺术特别版 8GB内存 黑色陶瓷尊享版 256GB ', 'price' => '4299'],
            ['name' => ' 小米6X 全网通版 4GB内存 64GB ', 'price' => '1599'],
            ['name' => ' 小米5X 4GB+64GB ', 'price' => '1299'],
            ['name' => ' 红米Note 5 全网通版 3GB内存 32GB ', 'price' => '1099'],
            ['name' => ' 黑鲨游戏手机 标准版 ', 'price' => '2999'],
            ['name' => ' 红米5 Plus 3GB+32GB ', 'price' => '1399'],
            ['name' => ' 红米S2 3GB+32GB   ', 'price' => '1000'],
            ['name' => ' 小米Note 3 4GB+64GB ', 'price' => '1200'],
            ['name' => ' 小米Max 2 4GB+64GB ', 'price' => '1699'],
            ['name' => ' 小米8 ', 'price' => '2699'],
            ['name' => ' 小米8 SE ', 'price' => '1799'],
            ['name' => ' 小米MIX2 全网通版 6GB内存 黑色陶瓷 128GB ', 'price' => '2799'],
        ];
    }

    function numberRand($begin = 0, $end = 15, $limit = 5){
        $rand_array = range($begin, $end);
        shuffle($rand_array); //调用现成的数组随机排列函数
        return array_slice($rand_array, 0, $limit); //截取前$limit个
    }
}